package com.fm.demo.activity

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.blankj.utilcode.util.LogUtils
import com.fm.common.base.BaseBActivity
import com.fm.demo.databinding.ActivitySwitchZBinding

class SwitchZActivity : BaseBActivity<ActivitySwitchZBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.szViewBlue.setOnClickListener { v: View ->
            LogUtils.e("blue")
            if (v.layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT) {
                return@setOnClickListener
            }
            switchZ(binding.szRoot, binding.szViewBlue, binding.szViewGreen)
        }
        binding.szViewGreen.setOnClickListener { v: View ->
            LogUtils.e("green")
            if (v.layoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT) {
                return@setOnClickListener
            }
            switchZ(binding.szRoot, binding.szViewGreen, binding.szViewBlue)
        }
    }

    private fun switchZ(rootView: FrameLayout, smallView: View, fullView: View) {
        val smallParams = smallView.layoutParams
        val fullParams = fullView.layoutParams
        smallView.layoutParams = fullParams
        fullView.layoutParams = smallParams
        rootView.removeAllViews()
        rootView.addView(smallView)
        rootView.addView(fullView)
    }
}